import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

import org.junit.Test;

import jdk.jfr.Timestamp;

public class TCPTest1 {
    @Test
    public void client(){
        Socket socket=null;
        OutputStream ops=null;
        File file=new File("E:\\java学习\\code\\day12\\java1\\src\\1.jpg");
        try {
            FileInputStream fips = new FileInputStream(file);
            InetAddress iAddress=InetAddress.getByName("10.175.216.213");
            socket=new Socket(iAddress, 8888);
            ops= socket.getOutputStream();
            int len;
            byte[] buffer=new byte[20];
            while((len=fips.read(buffer))!=-1){
                ops.write(buffer,0,len);
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally{
            if(socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            if(ops!=null){
                try {
                    ops.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
